package com.tucy.logistics.modules.vehicle.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tucy.logistics.common.dto.vehicle.QueryVehicleDto;
import com.tucy.logistics.common.entity.vehicle.VehicleInfo;
import com.tucy.logistics.common.entity.vehicle.VehicleType;
import com.tucy.logistics.common.result.Result;
import com.tucy.logistics.modules.vehicle.service.VehicleInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * author: tcy
 * createDate: 2023/10/12
 * description:
 */
@Api(tags = "车辆管理")
@RestController
@RequestMapping("/vehicleInfo")
public class VehicleInfoController {

    @Autowired
    VehicleInfoService vehicleInfoService;

    @ApiOperation(value = "查询车辆")
    @PostMapping("/queryVehicleInfo")
    public Result<Page<VehicleInfo>> queryVehicleInfo(@RequestBody QueryVehicleDto queryVehicleDto) {
        return Result.success(vehicleInfoService.queryVehicleInfo(queryVehicleDto));
    }

    @ApiOperation(value = "车辆详情")
    @GetMapping("/queryVehicleInfoDetails/{id}")
    public Result<VehicleInfo> queryVehicleInfoDetails(@PathVariable("id") String id) {
        return Result.success(vehicleInfoService.queryVehicleInfoDetails(id));
    }

    @ApiOperation(value = "增改车辆")
    @PostMapping("/saveUpdateVehicleInfo")
    public Result<Boolean> saveUpdateVehicleInfo(@RequestBody VehicleInfo vehicleInfo) {
        return Result.success(vehicleInfoService.saveUpdateVehicleInfo(vehicleInfo));
    }

    @ApiOperation(value = "删除车辆")
    @GetMapping("/deleteVehicleInfo/{id}")
    public Result<Boolean> deleteVehicleInfo(@PathVariable("id") String id) {
        return Result.success(vehicleInfoService.getBaseMapper().deleteById(id) == 1);
    }

}
